package org.example.travel_web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.travel_web.dto.PageResult;
import org.example.travel_web.dto.attraction.AttractionDetail;
import org.example.travel_web.dto.attraction.AttractionReq;
import org.example.travel_web.dto.attraction.PageReq;
import org.example.travel_web.dto.attraction.PageResp;
import org.example.travel_web.entity.AttractionCategoriesET;
import org.example.travel_web.service.AttractionCategoriesService;
import org.example.travel_web.service.AttractionsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/attraction")
@Tag(name = "景点管理")
public class AttractionController {
    @Resource
    private AttractionsService attractionsService;
    @Resource
    private AttractionCategoriesService attractionCategoriesService;

    @GetMapping
    @Operation(summary = "景点分页")
    public PageResult<PageResp> pageResult(@Valid PageReq pageReq) {
        return attractionsService.pageResult(pageReq);
    }

    @GetMapping("/category")
    @Operation(summary = "获取景点分类")
    public List<AttractionCategoriesET> getAttractionCategories() {
        return attractionCategoriesService.list();
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取景点详情")
    @Parameter(name = "id", description = "景点 ID", required = true, in = ParameterIn.PATH)
    public AttractionDetail getAttractionDetail(@PathVariable Integer id) {
        return attractionsService.getAttractionDetail(id);
    }

    @PostMapping
    @Operation(summary = "新增景点")
    public void addAttraction(@Valid AttractionReq req) {
        attractionsService.addAttraction(req);
    }

    @PutMapping
    @Operation(summary = "修改景点")
    public void updateAttraction(@Valid AttractionReq req) {
        attractionsService.updateAttraction(req);
    }

    @DeleteMapping
    @Operation(summary = "删除景点")
    @Parameter(name = "ids", description = "景点 ID 数组", required = true, in = ParameterIn.QUERY)
    public void deleteAttraction(@RequestParam Integer[] ids) {
        attractionsService.deleteAttraction(ids);
    }
}
